﻿using System.Collections.Generic;
using System.Web.Http;
using DefaultConnection;
using MementoWeb.Models;

namespace MementoWeb.Controllers
{
    public class TaskController : ApiController
    {
        private readonly IDataRepository _dataRepository; 

        public TaskController(IDataRepository dataRepository)
        {
            _dataRepository = dataRepository;
        }

        public IEnumerable<Task> Get()
        {
            return _dataRepository.GetAllTasks();
        }

        public Task GetById( int id )
        {
            return _dataRepository.GetTaskById(id);
        }

        public void CreateNew( Task task )
        {
            _dataRepository.CreateNewTask(task);
        }

        public void Update( Task task )
        {
            _dataRepository.SaveTaskChanges(task);
        }

        public void Delete( int id )
        {
            _dataRepository.DeleteTask(id);
        }
    }
}
